package com.pm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/test")
public class TestController {
    
    @Autowired
    private PasswordEncoder passwordEncoder;
    
    @GetMapping("/encode-password")
    public String encodePassword(@RequestParam String password) {
        String encoded = passwordEncoder.encode(password);
        String existing = "$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iKTVEFDi";
        boolean matches = passwordEncoder.matches(password, existing);
        boolean newMatches = passwordEncoder.matches(password, encoded);
        
        return String.format(
            "Password: %s\n" +
            "Existing hash: %s\n" +
            "Matches existing: %s\n" +
            "New hash: %s\n" +
            "Matches new: %s",
            password, existing, matches, encoded, newMatches
        );
    }
}